/*
 * Copyright (C) 2008-2010 Oliver Horn.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.funcj;

import com.google.common.base.Function;

/**
 * A container which supports transformation of its members by a {@code Function}.
 *
 * @author Oliver Horn
 *
 * @param <T> the transformable member type
 */
public interface Transformable<T> {

	/**
	 * Creates a new, compatible container object where each member of type {@code T}
	 * is transformed by the given {@link Function}.
	 *
	 * <p>An implementation must satisfy the following laws:
	 *
	 * <pre>
	 *   obj.transform(Functions.identity()).equals(obj)
	 *   obj.transform(Functions.compose(f, g)).equals(obj.transform(g).transform(f))
	 * </pre>
	 *
	 * <p>Additionally, a transformation should return a compatible container object.
	 *
	 * @param <V> the result type of the transformed member
	 * @param function function to be applied
	 * @return transformed container
	 */
	public <V> Transformable<V> transform(Function<? super T, V> function);
}
